home *** CD-ROM | disk | FTP | other *** search
/ Chip 2000 May / Chip_2000-05_cd1.bin / sharewar / FFE / GRAPH.SWG / 0040_Andrew Toolkit ATK (CMU) Specs.pas < prev    next >
Pascal/Delphi Source File  |  1997-05-11  |  13KB  |  367 lines

  1. Data stream formats in the Andrew User Interface System
  2.  
  3. Wilfred J. Hansen 
  4. Andrew Consortium 
  5. Carnegie Mellon University 
  6.  
  7.  
  8. (The Andrew Toolkit (ATK) is the architecture and tools for building
  9. application in the Andrew User Interface System.) 
  10.  
  11.  
  12. In order to support the inclusion of arbitrary objects in multi-media
  13. editors, the Andrew Toolkit requires data objects to conform to a set of
  14. conventions for their file representation.  A data object must write its
  15. data enclosed in a begin/end marker pair.  The marker must include a tag
  16. denoting the type of the object being written and a unique identifier,
  17. used for referencing the data object by other data objects.  If a data
  18. object includes other data objects, they must be properly nested.  The
  19. begin/end markers make it possible to find the data associated with an
  20. object without actually parsing the data. 
  21.  
  22. For example, a text with an embedded picture has the format: 
  23.  
  24. \begindata{text,1} 
  25. <text data>
  26. \begindata{picture,2} 
  27. <picture data> 
  28. \enddata{picture,2} 
  29. \view {pictureview,2} 
  30. <more text data> 
  31. \enddata{text,1}
  32.  
  33. In order to transport files across most networks, data streams use only
  34. printable 7-bit ASCII characters, including tab, space and new-line, and
  35. keep line lengths below 80 characters. 
  36.  
  37. ____________________________________
  38. Text format 
  39.  
  40. Text data streams in the Andrew User Interface System follow the general 
  41. principles for Andrew Toolkit data streams.  The overall structure 
  42. of a text data stream is 
  43.  
  44. A. \begindata line 
  45. B. \textdsversion line 
  46. C. \template line 
  47. D. definitions of additional styles 
  48. E. the text body itself 
  49. F. styled text
  50. G. embedded objects in text body 
  51. H. \enddata line 
  52.  
  53. Subsequent sections of this document describe each of these components. 
  54.  
  55. As usual in ATK, the appropriate way to read or write the data stream is
  56. to call upon the corresponding Read or Write method from the AUIS 
  57. distribution.  Only in this way is your code likely to continue to work in 
  58. the face of changes to the data stream definition.  Moreover, there are 
  59. a number of special features--mostly outdated data streams--that are 
  60. implemented in the code, but not described here. 
  61.  
  62.  
  63. A. \begindata line 
  64.  
  65. Standard ATK begindata line having the form 
  66.  
  67. \begindata{text,99999}
  68.  
  69. where 99999 is some identifying number unique within this data stream. 
  70.  
  71.  
  72. B. \textdsversion line 
  73.  
  74. This line always has the form 
  75.  
  76. \textdsversion{12} 
  77.  
  78. There exist files written with earlier data stream versions having values 
  79. other than 12.
  80.  
  81.  
  82. C. \template line 
  83.  
  84. If the file utilizes a style template, there will be a line of this form: 
  85.  
  86. \template{default} 
  87.  
  88. where 'default' is whatever template name is used.  This template name is 
  89. the prefix of a filename.  The name is appended with the suffix ".tpl" and 
  90. sought in the directories named in the user's atktemplatepath preference 
  91. value.  If there is none, the default directory is $ANDREWDIR/lib/tpls.
  92.  
  93. 'default' is the most usual template name.  Every installation of AUIS 
  94. is expected to have $ANDREWDIR/lib/tpls/default.tpl and its styles are 
  95. not defined further in the document. 
  96.  
  97.  
  98. D. definitions of additional styles 
  99.  
  100. A document may define and use styles that are not in the template.  Each 
  101. such definition is two or more lines: 
  102.  
  103. \define{internalstylename
  104. menuname 
  105. attribute 
  106. . . . 
  107. attribute} 
  108.  
  109. The internalstylename is lower case and may have digits, but no spaces.
  110. There may be no menuname, in which case there is an empty line;  if there 
  111. a menuname line, it is of the form 
  112.  
  113. menu:[Menu card name,Style name] 
  114.  
  115. If there are no attributes, the closing '}' appears at the end of the
  116. menuname line.  Each attribute line is of the form 
  117.  
  118. attr:[attributename basis units value] 
  119.  
  120. where the first three are strings and the fourth is an integer, possibly 
  121. signed.  The specific values allowed are beyond the scope of this document;
  122. they do correspond closely to values in style.H. 
  123.  
  124.  
  125. E. the text body itself 
  126.  
  127. Text is represented by itself.  n consecutive newlines in the text are
  128. represented by n+1 newlines in the data stream.  Single newlines are used 
  129. to break the stream into lines of less than 80 bytes;  these are ignored 
  130. when the file is read.  Earlier data stream versions required a sapce before 
  131. a newline if there was to be a space in the text;  version 12 invents a 
  132. space before the newline if one is not there.  The latter is prevented by 
  133. ending the line with a single backslash (\).  If a sentence ends a line and
  134. has more than one space after its punctuation, the additional spaces must 
  135. appear at the start of the next line.  The characters backslash, left 
  136. brace, and right brace are always preceded in the text with a backslash. 
  137.  
  138. There is a convention for representing non-ASCII ISO-8859 characters, but 
  139. I don't know what it is offhand.
  140.  
  141.  
  142. F. styled text 
  143.  
  144. If text in the body is to be displayed in a style, e.g. italic, the text is 
  145. preceded with
  146. \internalstylename{ 
  147. and followed by a closing curly brace.  The internal style name is 
  148. one of the names defined either in the template or in a \define line. 
  149.  
  150.  
  151. G. embedded objects in text body
  152.  
  153. When an object is embedded in a text body, two items appear: the data 
  154. stream for the object and a \view line.  The \begindata for the object is 
  155. always at the beginning of a line.  (The previous line is terminated with 
  156. backslash if there is to be no space before the object.)  The \enddata 
  157. line for the object always ends with a newline (which is not treated as a
  158. space).  
  159.  
  160. The \view line has the form: 
  161.  
  162. \view{rasterview,8888,777,0,0} 
  163.  
  164. In future data stream versions, other items may appear before the '}'; each 
  165. such item is preceded by a comma.  The first item in the list is the textual 
  166. name of the view object to be used to display the dataobject.  The second 
  167. item is the identifing integer that also appears in the \begindata for the 
  168. object.  The third value is ignored.  The fourth and fifth items are 
  169. usually zero;  however, if non-zero the specify the desired width and height
  170. to display the object. 
  171.  
  172.  
  173. H. \enddata line 
  174.  
  175. Has the form
  176.  
  177. \enddata{text,99999} 
  178.  
  179. that is, it is the same as the \begindata line, but has 'end' instead 
  180. of 'begin'. 
  181.  
  182.  
  183.  
  184. ____________________________________ 
  185. Format of ATK raster images 
  186.  
  187. The raster data object writes a standard ATK data stream beginning with
  188. a \begindata line and ending with a \enddata line.  Between these comes 
  189. a header and possibly an image body. 
  190.  
  191. The first line of the header looks like this: 
  192.  
  193. 2 0 65536 65536 0 0 484 603
  194.  
  195. Where the values are these: 
  196.  
  197. RasterVersion:  '2'  
  198. This specification describes the second version of this encoding. 
  199.  
  200. Options: '0' 
  201. This field may specify changes to the image before displaying it: 
  202.  
  203. raster_INVERT(1<<0)/* exchange black and white */ 
  204. raster_FLIP(1<<1)/* exch top and bottom */ 
  205. raster_FLOP(1<<2)/* exch left and right */
  206. raster_ROTATE(1<<3)/* rotate 90 clockwise */ 
  207.  
  208. xScale, yScale:  '65536 65536' 
  209.  
  210. These scale factors affect the size at which the image is printed. 
  211. The value raster_UNITSCALE (136535) will print the image at
  212. approximately the size on the screen.  The default scale of 
  213. 65536 is approximately half the screen size.  (It is not 
  214. exactly half screen size in an effort to simplify scaling on 
  215. 300-dots-per-inch printers.) 
  216.  
  217. x, y, width, height:    '0 0 484 603'
  218.  
  219. It is possible for a raster object to display a portion of an 
  220. image.  These fields select this portion by specifying the 
  221. index of the upper left pixel and the width and height of the 
  222. image in pixels. 
  223.  
  224. In all instances so far, x and y are both zero and the width 
  225. and height specify the entire raster. 
  226.  
  227. The second header line specifies the actual raster in one of three forms; 
  228. but only the first of these forms is actually used. 
  229.  
  230. First form: 
  231. bits 10156544 484 603 
  232.  
  233. RasterType: 'bits' 
  234. This form. 
  235. RasterId: '10156544'
  236. An identifier so other raster objects can refer to this one. 
  237. Usually this is the same identifier as in the \begindata line. 
  238. Width, Height:  '484 603' 
  239. Describes the width of each row and the number of rows. 
  240. This many rows follow one subsequent lines. 
  241.  
  242. Second form:   refer 10135624 
  243. The current data object does not have the bits, but refers to the 
  244. bits as stored in another data object (which should appear earlier 
  245. in the same data stream.)   'refer' identifies this form and 
  246. the integer is the identifying number. 
  247.  
  248. Third form:   file 10235498 filename path 
  249. The raster is not in the current data object, but is in a file. 
  250. 'file' identifies this form.  The id number '10235498' allows 
  251. this raster data to be refered to by a 'refer' form.  The filename 
  252. is the full pathname of the file.  Path is the element of a 
  253. "rasterpath" list against which the filename was resolved.
  254. (This is not fully implemented.  The idea is to acheive a 
  255. measure of recovery in case the file is moved.) 
  256.  
  257.  
  258. In the first form ('bits'), the header is followed by lines specifying the 
  259. image.  There is at least one line per raster row, though some rows may take
  260. more lines.  The bits of a row are encoded in blocks of eight; a multiple 
  261. of 8 bits are specified, though trailing bits will be ignored after reading 
  262. the row.  Following the last bits for a row are a space, a vertical bar (|), 
  263. and a newline.  Basically, white space is to be ignored, so the bytes of the 
  264. encoding are broken into blocks of 13 or 14 bytes separated with tabs. 
  265.  
  266. The bits of the row are run-length encoded by bytes.  That is, a sequence 
  267. of identical bytes will be represented in only a few bytes rather than 
  268. at full length.  Hexadecimal is a subset of this encoding with a one bit 
  269. representing black and zero for white.  Here is the 
  270. interpretation of each range of byte values: 
  271.  
  272. control characters and space: 
  273. Ignored. 
  274. @ [ ] ^ _ ` } ~ 0x7F and all characters with high bit set: 
  275. These are errors, but at present they are ignored. 
  276. { \: 
  277. Illegal end of line.  Treat as end of row.
  278. |: 
  279. Legal end of row.  If there have not been enough 
  280. codes for the entire width, pad with white bits. 
  281. 0x21 ... 0x2F  (punctuation characters) 
  282. The next two bytes specify a hex value.  This value is 
  283. to be repeated in the row the number of times given
  284. by c-0x1F, where c is the input code.  (That is, 0x21 means 
  285. to repeat the byte two times, 0x22 three times, and so on.) 
  286. 0x30 ... 0x3F  (digit or punctuation) 
  287. This is a hex digit and encodes one byte of the row 
  288. with the value c-0x30. 
  289. A ... F  a ... f
  290. These are hex digits with values 0xA ... 0xF. 
  291. g ... z 
  292. Multiple white bytes.  c-'f' bytes of white are generated into row 
  293. G ... Z 
  294. Multiple black bytes.  c- 'F' bytes of black are generated into row 
  295.  
  296.  
  297.  
  298.  
  299. \begindata{text,538375988} 
  300. \textdsversion{12} 
  301. \template{default}
  302. \define{global 
  303. \define{up15 
  304. menu:[Justify,Up15] 
  305. attr:[Script PreviousScriptMovement Point -15]} 
  306.  
  307. This is text in the document.  \italic{This is 
  308. italic.}  These two lines are one paragraph. 
  309.  
  310.  
  311. This paragraph is preceded by two newlines, but it will be 
  312. displayed with only one blank line between it and the previous one.
  313.  When two space are required between words, the second 
  314. must appear at the beginning of a line.  When a newli\ 
  315. ne is not to be replaced with a space, it must be preceded 
  316. with backslash. 
  317.  
  318. \begindata{bp,9233088}
  319. \enddata{bp,9233088} 
  320. \view{bpv,9233088,38,0,0} 
  321.  
  322. This second page has a raster on it. 
  323.  
  324. \begindata{raster,10156544}
  325. 2 0 68266 68266 0 0 484 603 
  326. bits 10156544 484 603 
  327. zzzg | 
  328. zzzg | 
  329. 7fZZHfeKfeOc0g | 
  330. . . .
  331. zzzg | 
  332. \enddata{raster, 10156544} 
  333. \view{rasterview,10156544,31,0,0} 
  334.  
  335.  
  336. \enddata{text,538375988}
  337.  
  338. -----------------------------
  339.  
  340.  
  341. The only immediate comment I would add is that, if you come across a
  342. file which purports to be an AUIS raster file, it may be either of two
  343. things: 
  344.  
  345. A) A raster datastream, as defined in Fred's document under "Format of
  346. ATK raster images." The first line of this file would be 
  347. \begindata{raster,99999} 
  348. (with an arbitrary ID integer in place of the 999999). This would be
  349. followed by the header and possibly the image body, and then the final
  350. line would be 
  351. \enddata{raster,99999} 
  352. (with the same integer.) 
  353.  
  354. B) A text datastream (or some other kind of datastream) containing a
  355. raster as an embedded object and no other data. This is not the
  356. preferred way to store a raster image, but it tends to happen every now
  357. and then. 
  358. In this case, the raster datastream will occur, as described above,
  359. somewhere within the larger datastream. It is legal to read in lines and
  360. throw them away until you find a line that begins
  361. \begindata{raster, 
  362. (The backslash will always be the first character on the line.) You then
  363. read in the datastream until the \enddata line occurs, and ignore the
  364. rest of the file. (You can compare the ID numbers as a consistency
  365. check). 
  366.